Similar improvement to calculateMaxK as what I did for calculateStepK
(#238)