Improve compatibility with older versions of PHP

Remove anonymous function and make as a standard function - users have reported problems with older versions of PHP.