Rewrote stacks implementation