Refactoring, and simplification to original codebase.