optimize script and api;