implement clustering functions

Closes #3.