More cleaning, and reduce scope of some variables.