[minor] Allow `.write` to be pre-defined by using a different option for child check
[minor] Move the function creation out of the for loop