Move assert out of foreach loop, minor cleanup.