refactored code from the test program into the package