Fix stack calculation