refactored main controller