stack refactoring