refactor task sorting and extend to pooled tasks