FIX Issue #39 Our of order CodeBlocks

Also fixes some other odd errors I've been getting.
And make generated code easier to read.
Merge pull request #70 from TonyCallear/master

FIX Issue #39 Out of order CodeBlocks