Simplification of the ldf code

I hope the code is more readable and maintainable.
Also, I hope I have not broken anything.