First refactor of api.