Refactor controllers to transfer logic to models