Fixed various issues on the Python 3 port