I made changes to lines 528-531 and didn't touch anything else, but it does look like the order of call_hooks and apply_metadata was transposed. I don't know if the order is significant, but if a call hook interacts with the metadata then it might matter.