move script code into module for testing