finished refactor to python3, struggling with type
tidied up some funcs