Modified the stack implementation