Refactor task to handler