fixed many small bugs
need to reset current indexes before rebuilding, otherwise we have duplicated entries