Issue 203 full query refactoring

Some more query refactorings (ref. #203)