Python 3 support

Based on @lorddaedra's work in PR #27.