refactor error messages to be generic and take form object as parameter