Reduce code duplication in atfork