Fix some variable naming and scope bugs.