Removed unused code.
Updated looping logic.