Fixed out of bounds loop