Refactoring and code cleaning