diff --git a/AI_Attendence_Program/Main.py b/AI_Attendence_Program/Main.py
index cd0f8960..f2c6a64e 100644
--- a/AI_Attendence_Program/Main.py
+++ b/AI_Attendence_Program/Main.py
@@ -9,14 +9,14 @@
 PersonName = []
 mylist = os.listdir(path)
 print(mylist)
-# for separating the name from their extensions
+
+# For separating the name from their extensions
 for cu_img in mylist:
     current_Img = cv2.imread(f'{path}/{cu_img}')
     Images.append(current_Img)
     PersonName.append(os.path.splitext(cu_img)[0])
 print(PersonName)
 
-
 def encodings(images):
     encodelist = []
     for img in images:
@@ -25,13 +25,11 @@ def encodings(images):
         encodelist.append(encode)
     return encodelist
 
-
 encode_list_Known = encodings(Images)
 print("ALL ENCODING FOUND!!!")
 
-
 def attendance(name):
-    with open('Attendence.csv', 'r+') as f:
+    with open('Attendance.csv', 'r+') as f:
         myDataList = f.readlines()
         nameList = []
         for line in myDataList:
@@ -43,11 +41,19 @@ def attendance(name):
             dStr = time_now.strftime('%d/%m/%Y')
             f.writelines(f'\n{name},{tStr},{dStr}')
 
-
 cap = cv2.VideoCapture(0)
 
+# Check if the webcam was opened successfully
+if not cap.isOpened():
+    print("Error: Could not access the webcam.")
+    exit()
+
 while True:
     ret, frame = cap.read()
+    if not ret:
+        print("Error: Failed to read from the webcam.")
+        break
+
     faces = cv2.resize(frame, (0, 0), None, 0.25, 0.25)
     faces = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
 
@@ -63,7 +69,6 @@ def attendance(name):
         if matches[matchIndex]:
             name = PersonName[matchIndex].upper()
             y1, x2, y2, x1 = faceLoc
-            #y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4
             cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 0, 0), 2)
             cv2.rectangle(frame, (x1, y2 - 35), (x2, y2), (0, 255, 0), cv2.FILLED)
             cv2.putText(frame, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
@@ -72,5 +77,6 @@ def attendance(name):
     cv2.imshow("camera", frame)
     if cv2.waitKey(10) == 13:
         break
+
 cap.release()
 cv2.destroyAllWindows()