clustering, various modifications

Need to comment these in more detail.