Refactored to add Flash message for errorMessage and successMessage