revised top_down algorithm according to Dan's suggestions -KL