added checking for file exists