Refactor dropdown menu code.