Simple Cleanup

Most of the issues I was looking at were already merged back into the mainline. Did some code refactoring along the way that should make things easier to read. Please take a look and see if it help you too.