refactored clustering