Minor refactoring and cleaning of the code