Refactor using handler functions