Add helper function to simplify pointer error checking