refactoring to a single handler