Fix cached values not being set in correct scope