main loop implemented