improved handling of pattern folding rules for cell data structures
improved detection of reachaing the end of the rule
bug fixes