made code on prob 2 better