DO NOT MERGE (for review): Python 3 compatibility

I have not thoroughly tested this fix, but wanted to provide a preview of my ideas on how to add Python 3 support.

Feedback welcomed!