improving lib.php and adding waypoints plugin