added file check to code