fix indexing bug in func CompleteTask