Python 3 compatibility and simplifications