added some functions and php code