Refactor of API logic.