Python 3 support for CPT

Fixed some problems in dual compatibility with Python 2 and Python 3.
Completes Pull Request #56.