implemented suggestions from code review and refactored invoke