Fix capturing funciton