BTW - do you really need two separate implementations of `compute_gauss_newton_step` (here and above around line 500)? It seems that they are very similar, and you could potentially reduce them to one helper function that would be called twice.