Refactoring for better stack control