added docs, and refactored some assertions into enclosed modules.