Finishing part 2 main logic