Added heap and improved efficiency of merge in reduce step