added a new test script, refactored the code