finished version of exercise 2 and part of 3