Fixed a bug where multiple stacks weren't taken into account