refactored error message creation