bugs:  needed to be reintialized in the foreach loop line 280 lib.php