Reformatted some loops.
Added a few asserts.