Some refactoring to clean the code