refactor getStackPivotDistance, based on PR1 (submitted by yegle)