Fixed potential out of bounds exception