I accidentally attached the Dmitry's original patch file, that contains both the merged and unmerged fixes. Further, it appears that Dmitry's original patch handles the case where hs-hide-all is called in the attached sample perl script, BUT it does not handle the case where hs-hide-level is called with the point at the end of the buffer. I'm attaching a new patch that ONLY contains the pertinent changes and that addresses the second issue also.