added detection to handle if a file exists or not