Add scanner_dispatcher_thread and code cleanup