misc fixes and python 3 compat.