Refactored Main