@winni,
As @wp pointed out, improving your original simple code would provide a (no doubt delightful) 'exercise in logical thinkining'. I never said I would not do it but I surely have no complaints if you did it first!
BTW, both solutions (yours and @howardpc's) work very well, they are just different implementations.
Thank you!
Best regards,