refactor handler functions