Fixed buildIndex
Made application more robust with input args