refactoring adding to empty array