Core code which controls the capture process.