Moves initialization of variable to after check if key exists