Refactoring the code structure