Fixed compiler warnings and potentional overflow
modified call to msd.Sort to match updated interface