Move error checks to the helper functions