okay, this is mostly working an I understand what it needs to do now, but it's
still ugly/inelegant...