Problem 2 initial clean up

Made my code for the second function easier to follow (based on my code
from the first function).