refactored success/error messages returned by ajax