added the loop and logging