added correct error check