Correctly returning cached value if it was already calculated