Refactoring and small changes

above