@OP, just a precautionary note.. when dealing with heredocs, there cannot be a space after <<<ITEM nor ITEM;
When I highlighted both those lines individually in your code, there is a tailing space in both.. by contrast, NogDog's doesn't (which is how it is supposed to be.. otherwise you will receive parsing errors).. It's one of those nuance 'gotchas' that if you are not careful, will snag you everytime.