Thank you @Victor for your great support! In the end I have decided to keep the @JL_LJ solution, as it was easier for me to implement it!
Thank you @JL_LJ ! I have implemented it and it is functional!