refactoring the code structure