Refactor list-tasks to handle more cases