Major refactoring for simplification