refactoring of observer pattern