Typo.
Remove useless foreach and add output buffering.