Refactoring Task Code