Fixes minor issue with queries being executed in the wrong order