Added error handling for failed ajax