Updated unrolled version of main loop