Basic Python 3 compatibility

Works, but hasn't received quite as much testing as I'd like.