refactored the test code to be more modular