factor query code