Refactor the error messages into their own function, have the other functions use it for error messaging