Refactor menu toggle code