Refactor stack into stack.js.