fixed main loop calc