added aggregate query functionality