A few fixes

Thanks for your code, it can be a life-saver not to have to migrate thousands of lines from a legacy project.

I had to make a few fixes for it to work on my customer's project. Here they are, hopefully they will be useful to others.