Add script to run tests; some code simplification