Optimize recursive_fill_tool