Adds some error checks