fixing undefined variable $newname