fix handling of empty stacks when determing which container to relocate and on which stack to move it