Removed use of remove method directly. Will call shutdown and only remove if there are no tasks left.