Fix bugs in run_tests