added extra check if file is a regular file