refactor handler