Fix Python 3 compatibility

Related to #21 and #28.