Move some more stuff to api. This change is incomplete.