Python3 compatibility

This will allow the code to run with Python 3 (tested with 3.3) as well as maintaining backwards-compatibility with 2.7