Wrote the navigation function.