Improve if condition to close the nav