Add Python 2 compatibility

Should be better now, but I haven't tested extensively.