refactored main