Refactored code to reuse success and failure handlers from existing code