Python 3 and 2 support. Cleanup. More error checking.