Refactoring the code: part 1