Fixes #828: refactored QueryBuilder::build()