Messages.OutputString moved inside the loop