Refactored test script