Python 3 compatibility fixes

Fixes #50