Support for Python 3

Code tested against existing functions in the unittest file