Improved complex string parsing