modifying nav script with cleaner code