refactor with new API logic