refactored to support additional merge clustering