stack refactored