refactor to use reduce and remove empty array declaration