Refactor code duplication in Handler