Refactoring and clean ups