Major refactoring of codebase.