Added conditional logic for error message

Suggested by Mike Peel.