Split functions into lib.php and locallib.php, so easier to access externally