Major refactoring on all fronts