Adding better logic for showing and hiding the navigation