Added comment lines to tell what each segment of code does.