Fixed method for extracting strings