Python 3 compatibility #2

A bit less messy adaptation... Tested with Python 2.7.5 and Python 3.3.2(Linux), not sure if it will work with Windows.