add more error condition checking