refact QueryHandler for sorting