Cleaned up buildindex to have more self-contained functions, and started the new flows