refactored error messages into functions.