part 1-refactored