Reduce code duplication in API