I have almost completed an optimized version of the script provided. It only still lacks the e-mail features and code to tweak output further and to your e-mail requirements.
But, please see for yourself. The scriptPlus