Minor refactorings around stack dist calculations.