Solved prob7, reusing prob10 code