fix bug of putting wrong level number in ToMiddle