Thanks for taking the time to reply. My messy code was a result of some testing thus the strange scoping. I used your code and the one from the first problem and I'm having the same problem.
I would try printlining the variables which are used in that line to see the values. This may be something specific to the module you are using not doing what you expect.