Added error handling to all ajax calls