Move some functions into PHP