Refactoring

Large refactoring for simplification