Move calcNumStacks to StackUtils and more