Fixed broken code after SQL refactor that I missed last time. Tested now and works as expected.