add query builder

also some other improvements and tweaks