Fix bug in calculation of ksq_max
(#470)