Refactor test scripts