make this work with python3 -- had to do list(dict.keys()) because
python3 has a dict_keys object.
fix some imports for python3