More documentation and code rewrite.