make scan_plugins recursive
reorder main routines into the order they are called