Python 3 compat and restructure of code.
Added grouping and a bunch more cleanup.
Fixed some text formatting issues.