added loop detection to backwards tree growth