code factorization in API