Minor refactoring of the code