Some fixes.
Fix a memory leak and some style issues.
Fix some mistakes. Damned macros.
Some cleanup.
Bunch of random cosmetic and miscelaneous fixes.