Added liberation of resources after a task is finished