Refactor task run system