fixed bug in observation caching code and cleaned few other codes