Refactored ticket controller code