sorting nodes in order to prevent frequent changes