Prettify and fix undefined variable error in script.php