Thanks to Galimzyaonva for the original work. I just translated the variable names, and a few other things.