Workaround for lack of Generators in PHP 5.4 and below