Was this entire code produced by GPT? I've found that it tends to typically die on my if it needs to write code that's longer than a few dozen lines. I once used chatgpt to convert a ~200 line js script to python and had to do it one functio