Removed redundant out-of-loop operations.