bugfixes in query function, move some presentation code to bdf-cli