Added expiry to cache and little bit of refactoring