Bugfixes + Python3 compatibility