Some code cleanup, mainly scoping.