Refactor to observer pattern