various fixes + py3 compatibility