Added possibility to merge based on frequency