python 3 support

- added Python 3 support, without breaking Python 2
- PEP 8 style fixes
- cleanups
- renamed some by mistake renamed functions