Fixed several issues related to python 3 compatibility (did not verify with python 2.7)