Refactoring and simplifications