write loop improvement