move success and failure handler to main