further refactoring of tasks code. Last commit before merge in the revert