Fixes error for empty tasklist

When a `tasklist` has no items, a KeyError is raised on line 406. I added a conditional to check whether the `tasklist` was empty, and in that case, iteration is stopped.