This algorithm uses only one loop
added an extra test just to be sure this is working