diff --git a/Decoder/decode_messages.py b/Decoder/decode_messages.py
index 6c6604cf44fda3b9845e1fe24ffa5e0b95be128d..c7742b543e049f0584edcf11faf6592c2791248d 100644
--- a/Decoder/decode_messages.py
+++ b/Decoder/decode_messages.py
@@ -6,7 +6,7 @@ from Decoder import dictionaries
 # specyficzne typy wiadomości
 need_adjustment = ["8_6", "24", "25", "26"]
 has_array = ['6_2', '6_7', '6_8', '6_9', '6_11', '7', '8_4', '8_7', '8_9', '8_10', '8_15', '20']
-shorter_than_expected = ["15", "16", "21"]
+shorter_than_expected = {"15":88, "16":96, "21":272}
 is_type_26 = ["26_00", "26_10", "26_01", "26_11"]
 
 
@@ -29,11 +29,19 @@ def decode_message(message):
         return "message data error"
 
     shorter_in_wild = ["24_A", "24_B"]
-    length_exceptions = shorter_in_wild + shorter_than_expected
+    length_exceptions = shorter_in_wild + list(shorter_than_expected.keys())
+    if message["type"] not in list(message_aggregates.datapartsBitlengths.keys()):
+        print("Nielegalny klucz: " + message["type"])
     expected_length = sum(message_aggregates.datapartsBitlengths[message["type"]])
     if (len(message["message"]) < expected_length) and (message["type"] not in length_exceptions):
         return "message data error"
 
+    if (message["type"] in list(shorter_than_expected.keys())):
+        min_length = shorter_than_expected[message["type"]]
+        if len(message["message"]) < min_length:
+            return "message data error"
+
+
     mainfields_bitstrings = split_to_fields(message)
     dataParts = decode_bitstrings(mainfields_bitstrings, message)
 
@@ -141,7 +149,7 @@ def split_to_fields(message):
     i = 0
     position = 0
     fragment = []
-    if message["type"] in shorter_than_expected:
+    if message["type"] in list(shorter_than_expected.keys()):
         field_count = len(shorten_message(message))
     else:
         field_count = len(message_aggregates.datapartsBitlengths[message["type"]])
@@ -172,7 +180,7 @@ def decode_bitstrings(bit_strings, message):
     i = 0
     dataParts = []
 
-    if message["type"] in shorter_than_expected:
+    if message["type"] in list(shorter_than_expected.keys()):
         field_count = len(shorten_message(message))
     else:
         field_count = len(message_aggregates.datapartsBitlengths[message["type"]])
diff --git a/Reader/read_file.py b/Reader/read_file.py
index 981969291dec1840fd3e1b844da74bb70f00bfd2..fcdf2a606987752fc208c92d5eb14e1c4bbe082c 100644
--- a/Reader/read_file.py
+++ b/Reader/read_file.py
@@ -1,5 +1,8 @@
 from Reader import counters
 from Aggregates import message_aggregates
+
+line_counter = 0
+
 def read_message(file):
     """Odczytuje Zwraca słownik typ wiadomości i informację użyteczną, 
     zlicza liczbę odczytanych wiadomości oraz liczbę wiadomości, których suma kontrolna jest błędna
@@ -72,6 +75,7 @@ def read_message_lines(file):
     elif len(lines) == 2:
         counters.double_line_counter += 1
 
+    line_counter + len(lines)
     return lines
 
 def extract_data(line):
@@ -208,6 +212,9 @@ def add_type(payload):
         type_bin = payload[0:6]
         type_dec = int(type_bin, 2)
 
+        if (type_dec < 1) or (type_dec > 27):
+            return "message data error"
+
         message = {
             "type": str(type_dec),
             "message": payload
diff --git a/main.py b/main.py
index 52fde381efd7b3175a5af20a4fc3d27d0f5357c7..86538c191e86ac129b4ee637231f9fa3768c7f18 100644
--- a/main.py
+++ b/main.py
@@ -14,6 +14,10 @@ def main():
         if message == "message data error":
             continue
         else:
+            # if message["type"] == "21":        
+            #     print("Linia: {}".format(reader.line_counter))
+            #     print("wiadomość: {}".format(message))
+            #     print("długość: {}".format(len(message["message"])))
             message_decoded = decoder.decode_message(message)
             if message_decoded == "message data error":
                 continue