Fixed out of bounds function.