Completely refactored extractFeatures method.