diff --git a/main.cpp b/main.cpp
index 1f3e1da91b500f698321f28d1bc751aa37967f1a..ccf9284b9411b96b62fb169a30c0c61f42e2aa35 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,6 +1,10 @@
 #include <filesystem>
 #include <fstream>
+#include <ios>
 #include <iostream>
+#include <string>
+
+#include <pcl/io/ascii_io.h>
 #include <pcl/io/pcd_io.h>
 
 void txt2pcd( std::filesystem::path input, std::filesystem::path output )
@@ -11,28 +15,71 @@ void txt2pcd( std::filesystem::path input, std::filesystem::path output )
     {
         pcl::PointCloud<pcl::PointXYZRGB> cloud;
 
-        while ( !inputFile.eof() )
+        // Read header
+        std::string line;
+        auto len = inputFile.tellg();
+
+        char buf{'\0'};
+
+        do
+        {
+            inputFile.get( buf );
+            if ( buf != '\0' && buf != '\n' )
+            {
+                line.push_back( buf );
+            }
+        } while ( buf != '\0' && buf != '\n' );
+
+        auto numberOfSpace = std::count( std::begin( line ), std::end( line ), ' ' );
+
+        if ( line.back() == ' ' )
+        {
+            if ( numberOfSpace > 0 )
+            {
+                --numberOfSpace;
+            }
+        }
+
+        auto const numArgument = numberOfSpace + 1;
+
+        inputFile.seekg( len, std::ios_base::beg );
+
+        pcl::PCDWriter pcdWriter{};
+        if ( numArgument == 6 )
         {
-            pcl::PointXYZRGB point;
+            while ( !inputFile.eof() )
+            {
+                pcl::PointXYZRGB point;
 
-            inputFile >> point.x;
-            inputFile >> point.y;
-            inputFile >> point.z;
+                inputFile >> point.x;
+                inputFile >> point.y;
+                inputFile >> point.z;
 
-            int r, g, b;
+                int r, g, b;
 
-            inputFile >> r;
-            inputFile >> g;
-            inputFile >> b;
+                inputFile >> r;
+                inputFile >> g;
+                inputFile >> b;
 
-            point.r = static_cast<char>( r );
-            point.g = static_cast<char>( g );
-            point.b = static_cast<char>( b );
+                point.r = static_cast<char>( r );
+                point.g = static_cast<char>( g );
+                point.b = static_cast<char>( b );
 
-            cloud.push_back( point );
+                cloud.push_back( point );
+            }
         }
+        else
+        {
+            inputFile.close();
+            pcl::ASCIIReader reader;
 
-        pcl::PCDWriter pcdWriter{};
+            auto ext = input.extension().string();
+
+            reader.setExtension( ext );
+
+
+            reader.read( input.string(), cloud );
+        }
 
         pcdWriter.writeBinaryCompressed( output.string(), cloud );
     }