working code for part 1