Improved navigate function