Initial port of clustering code from AS7