tree solution minor modifications.