Some cleaning and refactoring code