python3 compatibility, some bugfixes