Refactor navigate.js