big, nasty, unsquashed pull request

first pull of api-refactor branch from fork