more code cleanup and python2/3 compat changes.