code refatoring for AI client