optimized error message erb code and added test for error/success messages