Some Python3 fixes

Backward compatible with Python2