fixed a few bugs preventing Python3 migration