Pulled out error creation into a helper method