add more error case checking