Finished in theory the query aggregation algorithms, need to test it.