Fix bugs in test script