Fixed bugs in the navigation mainline.

gotoNext()/gotoPrev() is still rather messy, needs a major rewrite.