Revert "Revert this. Made a mess."

This reverts commit e061825111ca9f8e8cebab7cc72f085dcdc16db7.