Added Python 3 compatibility patches (in progress)