some code cleaning and refactoring