added better error checking for close; need to do the same for other places that read uint