Main logic

Now it's working.
Thank you for your guidance.