Refactor step 5 of build_tree() into create_leaves().