Code review and major cleanup.