Extracting problem to a more generic solver. Also switch the problem for...

... performance speedups.