updated extract function