ChatGPT provided not bad code. I started asking it to iteratively upgrade code and everything was going fine for the first 5 minutes. But then I faced with a lot of troubles that lead to the final result that I stated above. You can find final code here -