Refractored the error messages into their own function