It might be good to add a comment here as a reminder of why doc might be null