fixed extract function