(TK-3) Move things to let statements

Move various functions into let statements to increase
readability of code.