coded problem 12, needs improvement though