Yeah, I thought about making a common function for some of this, but there are enough subtle details that it would make it a bit complicated. Would you be okay if this was filed as a "code cleanup" bug?