Minor commenting changes

I put a comment at the beginning of each function to describe what it
is doing, and made the spacing more uniform.