Minor optimization & code convention fixes. Add documentation.