Improve format

Change-Id: I0a2c24dc3882d758319b16eb6b5a99af85487a77
Test loop invariant outside of the loop itself

Change-Id: I203937cb68c805a8692926aa1c9189ff0dd2c54c
Use more proper integer types

Change-Id: I4d87647d0a001ef24f9dde91cef85c72b44bcdd2