Fix stack implementation bugs.