Rearranged logic for #region/#endregion folding; worked around several corner cases; added test block for corner cases.