updated main loop