Working perfectly now. It ws a problem with the weights, specifically the indexing of them.