Add Python2/3 compatibility and clean up some old cruft.