Julius version of the code including a scan mode.
merged Julius Version with Joe's & Lorenzo's code.