shifted the code so that we use delayed messages instead of a loop on a different thread