After waiting for about a week to fix the broken functionality, I gave the breaking code to ChatGPT and told it to adjust it according to the use case. I did write the code but it did not work out of the box. Tweaked the response of chatGPT and baam. It worked.