Fix code style.

Quick pass at introducing a consistent style to the code and adding missing
comments.