Refactored common code for hiding menu