Pull cursor code out of viewmodels.

An attempt to make the code a bit more readable. I don't really want to
do a whole cursor re-write now, but it would be good to be able to see
the structure of the viewmodels more clearly.