Still bloated and ugly, and no error checking, but it works.