Fix bugs causing the test script not to work