Refactor task creation