Improve the navigation logic.