Full refactoring of codebase