Refactoring parts of the code