reworked main loop again