Thanks Paul - I swear I tried that too, but it seems to be working now! Thanks for the help.
I was working through the issue this morning, putting together a test case to show that this wasn't working for me, but since it is now working I suppose it can serve as a bit of reference for anyone else who runs in to the same sort of issues.
It's in Ruby with some external dependencies, but it's pretty easy to read and apply the concept to other languages.
Sam