Python 3 compatibility fix

I've fixed compatibility issues with Python 3. Tested on Python 2.7.3 and Python 3.2.3