add observer pattern and modified main