Refactoring code; split test script into separate file for functions usage; generalizing.