refactored the error print fn