syntax errors from #2 and output buffering fix

output buffering is not required, use the return transfer flag instead
also merged changes from #2 while I was at it to avoid merge conflicts