refactoring to enable task cleanup