Refactored main method