code refine for api