Main logic

Now it's working.
Yeah, sorry, I misunderstood something. It's all good.