Major refactoring and simplification