implement TaskService, refactor code