More Refactoring and fixes