working version for transition between different trees