improve coverage
move query assembly to a seperate function