optimizing featurization code