Formatting, documentation, and minor optimizations