refactored the main method to make it more testable