Improved the stack implementation for generic data types.