optimized code with single value variable, which replaced the array