works for prob 6