More refactoring and test fixing
Adding the rest of the changes