loop optimizations

also cut some overshooting lines