Many fixes to test running loop to support toplevel tests