Refactored Dynamic nav code