put in a couple of isopen sanity checks just to be safe (should
already be protected by higher level code).