variable renaming and some minor cleanup