Refactor to avoid using reduce() for old IE compat