refactor query
make specifying the collection optional
some cleanup