Main logic

Now it's working.
I see! That is simpler than before. thx