error message moved to function