Move the code from API to library so that the dependencies stay clean.