Fixed bug with number of tasks out of range