Add wait at end of process loop
Code tidyup