refactor stack