Fix indexing into threshold matrix to be consistent with threshold matrix file and separate code and data