added trees.length check
fixed bug