some stack refactoring