Move success and failure functions to controller