Refactored task factory. Optimized imports.