code reduction, loigc moved into main loop