finish code audit. formatting changes. added design doc