finished replace node code