refactor for array