Fix possible IndexError