refactored code to not use the array