now working main loop