adding more query and fixing sorting