Fix out of bounds exception