Optimize stack manipulation