Harden code and add documentation.