Adding observer pattern and fixed the bug where the last frame was hanging