More elegant helper method for error handling