WIP -- add tests, fix some dumb bugs