Implemented Observable pattern and fixed some potential bugs as indicated by intellij