Rewritten from scratch, should support both py2 and py3
Py3 compatibility
Py3 compatibility