storage: fixed query building for complex query objects