refactor handler to factory