add populating next right node and flatten btree