Changed the workings of the task planning code