commenting/format pass, and minor error-handling tweaks