getting queries about relations to work - more refactoring needed