Improve get_tasks to allow arbitrary filtering
Fix bug in get_tasks filtering