Fixed runtime errors in py3 version