Refactored main