first implementation to calculate meld