You inverted the region names, thereby asking for the opposite flow.
(Also, you keep calling the geometry routine making the region number to name conversion at each boundary crossing, which may have a considerable cost in CPU time, rather than calling the one making the region name to number conversion only once, as previously discussed and implemented).