add comments, make coding style more consistent, cleanup