Matches what the solver actually does. Checked against original C++ version for consistency.