Cleaned up code and made it sync with core DaoObserver code.