Fixed variable scope for `key`