refactor and edit api.