Modified the scan code to use timeouts.