Initial implementation, undocumented and untested, but it's a start