forEach was behaving badly for empty arrays