fixed looping issue and added additional comments