refactors stack