cleaned up main loop logic for cancelation and logging