refactoring of handlers + unit testing