Refactored value assignment to utilze array and for-each loop