refactoring out repeated pop action