Harden code, add documentation.