cw: more bugfixes. isolated all the cursor logic in a couple primitives.