Updated to cope with new similarity measures.