update code, add index, and fix bug