Python 3 support

This pull request is based on #31 and a lot of fix.