Check for defined values and if file exists

I have made the changes to the files. 

I hope they are correct.