Mechanism and specificity of the terminal thioesterase domain from the erythromycin polyketide synthase