Lots of code cleanup
Merge pull request #1 from Lambdanaut/master

Lots of code cleanup