Final refactoring fixes