Drafted new algorithm a bit further.

Put almost all pieces together to the phase where we have runnable code again.