Major refactor of codebase.