Added merge function for same IDs.