Refactor: move api bits to separate module.