py3 fixes - compatible with py2

had to do some fixes to get py2 and py3 compatibility.

did expensive tests and stuff. - works like a charm.