Complete rewrite to rely on common extensions in PHP 5.3 and later.
Changed internal variable name and some comments.
Minor text updates.