New leader api

this is the serious stuff of the new api, plus some refactoring of tests. it doesn't include some minor convenience additions i had planned to include just to get this stuff out and reviewed.