minor refactoring, addd complex query test (relates to #3)