General rewrite

Better comments and codebase