Refactored main file