major refactoring of stack core