Improved checking for multiple stacks.