refactory and optimize tasks