extract in a funciton