These were duplicated in 11 different files, and as they've gotten more complex a few inconsistencies have snuck in. Sharing them should make future changes easier and less bug-prone.