I've been using the same technique. If I describe precisely the technical steps to accomplish the thing I need with no mention of the overall use it happily generates the solution.
I think I've had more success recently with telling it to look at an old project I have in another folder on the system that does the thing I need to do. I've been using that technique to try and build a little self replicating worm to see it work in its own world. I keep jokingly telling people that we should just let a group on the 'good' side, whatever that might be, exploit and patch and move on. Inspired by Linux.Wifatch https://en.wikipedia.org/wiki/Linux.Wifatch