Add tests for error messages. Refactor flashes