use numeric path to find section after refresh (v2)

This is a better version of #1010 with proper commit messages explaining what's going on. Also I split the code that decides to move forward when there is no section n+1 into a separate commit. Perhaps we want to move backwards instead.

Fixes #336.