Fixing invalid use of let in variable scope