Python3 port. There are still a few problems...