Split lib.php and standardise file headers