add index and bug fix