Better config.php and some new functions on lib.php