Some code refactoring in handler