updated both imperative and functional to cache the new property values and save redundant computation