Modified code for null & improper filename