refactored following controller