building indexes; refactor