migrate to python3 and tidy up