Fix database errors (Index out of bounds)