Python 3 support

Some changes to work with python in version 2 and 3 - tested against a standalone project, but nothing more.