commenting and adding error checks