fix bug in extract function