Fixes for compiler warnings when building with VS2012, and a fix for an issue where the wrong format would be generated in some cases.