merged preclustering code into single new function