Revert to original loop

Original loop was correct, and slightly more efficient. Retain
initialization of ret to handle the case where passed in count is 0.