Move log out of loop