fixed potential out of bounds error