more error checking changes and comments