Thanks to Will Coon for the general idea.