restructured capture code for file capture.