added checking for existing file