This looks like the same code that gets executed for parents, except for some alignment variables -- can we abstract it to a function?