Initial import of code, inspired by conversation with Ben Keck