Removed broken recursiveCapture and replaced with working one. Removed global variable used in recursiveCapture