Simplification of the ldf code

I hope the code is more readable and maintainable.
Also, I hope I have not broken anything.
@hal3 please check the reductions using singleline (I hope they all have just one cost per sub-example, but this is not included in tests, so I cannot be sure).