moved all the working code out of the main wait loop into new function
do_scan()
Might rename that sometime soon though