Added clustering logic
Added tests