Refactored and cleaned main