Python3 compatibility

small changes which are backwards compatible with python 2.6+ and make the code base compatible with python 3