Fix debug script, pep8/refractor some code