added a if statement to check if the filename is not null