cleanup and rewriting my test script as a unittest