refacor code and api