adding error check to some operations