updated test script, code refactoring