libmn: move rebalancing code out of template
libmn: add static keyword to some functions