Added basic error checks