Codebase refactoring

initial merge