Fixing a bug in leaf assignment