fixed failing tests and some more refactoring around queryFactorType