Not necessary to fix, but it'd be nice if this code and the code in `list` could be factored out.