Beggining of refactoring the event handler