use count rather than foreach