Added task count calculation and tests.
Optimized queries and added remaining_time query draft.