minor code cleanups, turn some parameters into const refs.