Refactor header bar mode changing