so I ended up using asynchronous function with await. But the above code may have worked just fine. I would have to run it again to test it. Again, worked on preview, not on publish; as it turns out the browser queries were case sensitive, preview is not. Just an easy fix.