Simplify inner loop.

Code snippet by @jnothman.
Fix incorrect comment.
Fix comments.