Serious refactoring and simplification