Loop optimization