adjusted main loop for demo