fix bugs with index