finished problem 4, getting this up before 3 as I have to refactor that. takes far too long to run