clean up code, document, and fix lint