factorize code bit better for wrappers