solution to 3, modified 2