Newapi

I've started implementing the new api stuff. This isn't ready at all yet, but it's going to be a big chunk of work, and so it's probably best to get some eyes on it early.

I'd appreciate it if people would scan over this periodically.