Updated with a check for file
Added a line to throw an error