Add python3 compatibility

I've tested these changes with Python 3.3.1