fixed bug in mbkm representatives ids + added defensive copy() + added sorted representatives + minor refactoring to avoid code duplication