Factorize code.
Fix matrix layout elements updating.
First working implementation as intended of DND.