Fixed Loop and Added Tests