code for intermediate nodes