Working, but n^2 behaviour is too slow.
Tuning of cost function. Remove n^2 runtime.