moved non-indexed operations outside loops