Python 3 fork - should be refactored to support both py2 and py3