Refactored code to remove "array" and fixed update method