diff --git a/IMAPClient/.vs/IMAPClient/DesignTimeBuild/.dtbcache.v2 b/IMAPClient/.vs/IMAPClient/DesignTimeBuild/.dtbcache.v2
new file mode 100644
index 0000000000000000000000000000000000000000..df09084833b708ce523105e34e01cb51f85a5b8f
Binary files /dev/null and b/IMAPClient/.vs/IMAPClient/DesignTimeBuild/.dtbcache.v2 differ
diff --git a/IMAPClient/.vs/IMAPClient/v16/.suo b/IMAPClient/.vs/IMAPClient/v16/.suo
index 9925ffbd5866e5a6cf36f730c6b75f1092f4c851..67bc69d25d6721c985bc17ef8c6a5f90f663402d 100644
Binary files a/IMAPClient/.vs/IMAPClient/v16/.suo and b/IMAPClient/.vs/IMAPClient/v16/.suo differ
diff --git a/POP3Client/.vs/POP3Client/v16/.suo b/POP3Client/.vs/POP3Client/v16/.suo
index ec0a646a1044d4896ef7abb3d3efcc515a6e7774..9377488e89af0fd933113e12b0746493c68a51a7 100644
Binary files a/POP3Client/.vs/POP3Client/v16/.suo and b/POP3Client/.vs/POP3Client/v16/.suo differ
diff --git a/POP3Client/POP3Client/Program.cs b/POP3Client/POP3Client/Client.cs
similarity index 99%
rename from POP3Client/POP3Client/Program.cs
rename to POP3Client/POP3Client/Client.cs
index 5b73f923d284ac653e98c2bba78148614c02dfa7..4d7ce98fcac9379bc3eb9acd93b0c8c6e3be730c 100644
--- a/POP3Client/POP3Client/Program.cs
+++ b/POP3Client/POP3Client/Client.cs
@@ -9,7 +9,7 @@ using System.IO;
 
 namespace POP3Client
 {
-    class Program
+    class Client
     {
         static void Main(string[] args)
         {
diff --git a/POP3Client/POP3Client/bin/Debug/netcoreapp3.1/POP3Client.dll b/POP3Client/POP3Client/bin/Debug/netcoreapp3.1/POP3Client.dll
index 98af4ba4cd3438ac89fdb4c223c6e067363b08c3..f34fc26d21433defe5c12e8f3f961a7e79ad328b 100644
Binary files a/POP3Client/POP3Client/bin/Debug/netcoreapp3.1/POP3Client.dll and b/POP3Client/POP3Client/bin/Debug/netcoreapp3.1/POP3Client.dll differ
diff --git a/POP3Client/POP3Client/bin/Debug/netcoreapp3.1/POP3Client.pdb b/POP3Client/POP3Client/bin/Debug/netcoreapp3.1/POP3Client.pdb
index 74a1b508f632575641e36da06520e4488122db03..4db14db959e1175f42e109c7aab047b4c55dccf8 100644
Binary files a/POP3Client/POP3Client/bin/Debug/netcoreapp3.1/POP3Client.pdb and b/POP3Client/POP3Client/bin/Debug/netcoreapp3.1/POP3Client.pdb differ
diff --git a/POP3Client/POP3Client/obj/Debug/netcoreapp3.1/POP3Client.csproj.CoreCompileInputs.cache b/POP3Client/POP3Client/obj/Debug/netcoreapp3.1/POP3Client.csproj.CoreCompileInputs.cache
index d078cee873d4dbb7db1f786bbd28d18391892332..99fe6de985c0953b9810a983d579b359f053e24b 100644
--- a/POP3Client/POP3Client/obj/Debug/netcoreapp3.1/POP3Client.csproj.CoreCompileInputs.cache
+++ b/POP3Client/POP3Client/obj/Debug/netcoreapp3.1/POP3Client.csproj.CoreCompileInputs.cache
@@ -1 +1 @@
-ba938b7afaf50dc7b9bf1e93516b7840bc9053d1
+61089e71a388821e00b5f883e2a9474674b4e711
diff --git a/POP3Client/POP3Client/obj/Debug/netcoreapp3.1/POP3Client.dll b/POP3Client/POP3Client/obj/Debug/netcoreapp3.1/POP3Client.dll
index 98af4ba4cd3438ac89fdb4c223c6e067363b08c3..f34fc26d21433defe5c12e8f3f961a7e79ad328b 100644
Binary files a/POP3Client/POP3Client/obj/Debug/netcoreapp3.1/POP3Client.dll and b/POP3Client/POP3Client/obj/Debug/netcoreapp3.1/POP3Client.dll differ
diff --git a/POP3Client/POP3Client/obj/Debug/netcoreapp3.1/POP3Client.pdb b/POP3Client/POP3Client/obj/Debug/netcoreapp3.1/POP3Client.pdb
index 74a1b508f632575641e36da06520e4488122db03..4db14db959e1175f42e109c7aab047b4c55dccf8 100644
Binary files a/POP3Client/POP3Client/obj/Debug/netcoreapp3.1/POP3Client.pdb and b/POP3Client/POP3Client/obj/Debug/netcoreapp3.1/POP3Client.pdb differ
diff --git a/SMTPServer/.vs/STMPServer/v16/.suo b/SMTPServer/.vs/STMPServer/v16/.suo
index 793d7f32adc56240fe91d16da3dbbc9ad8c110e3..3c12b68db2d8278f226372efbef49ec36e762907 100644
Binary files a/SMTPServer/.vs/STMPServer/v16/.suo and b/SMTPServer/.vs/STMPServer/v16/.suo differ
diff --git a/SMTPServer/STMPServer/Program.cs b/SMTPServer/STMPServer/Server.cs
similarity index 50%
rename from SMTPServer/STMPServer/Program.cs
rename to SMTPServer/STMPServer/Server.cs
index f5f25a9b30a05723a65680045f0129be66837133..c6ea940b63e99f18d7aaf7432aa9cfe9bc489c94 100644
--- a/SMTPServer/STMPServer/Program.cs
+++ b/SMTPServer/STMPServer/Server.cs
@@ -2,50 +2,29 @@
 using System.Net;
 using System.Net.Sockets;
 using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
 using System.IO;
 using System.Collections.Generic;
+using System.Threading;
 
 namespace STMPServer
 {
-    class Program
+    class Server
     {
         static void Main(string[] args)
         {
-            //int[] ports = new int[] { 25000, 110, 143 };
-            int[] ports = new int[] { 110 }; // testing purposes
-            
             List<string> inbox = new List<string>();
+            //Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+            IPEndPoint iep_smtp = new IPEndPoint(IPAddress.Loopback, 25000);
+            IPEndPoint iep_pop = new IPEndPoint(IPAddress.Loopback, 110);
+            IPEndPoint iep_imap = new IPEndPoint(IPAddress.Loopback, 143);
+            
+            bool listening = true;
+            List<string> mails = new List<string>();
 
-            for (int i = 0; i < ports.Length; i++)
-            {
-                Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
-                IPEndPoint iep = new IPEndPoint(IPAddress.Loopback, 110);
-                socket.Bind(iep);
-                socket.Listen(1);
-
-                bool while_on = true;
-                List<string> mails = new List<string>();
-                
-                Console.WriteLine("SMTP Palvelin käynnissä portissa: " + 110);
-
-                while (while_on)
-                {                     
-                    mails = HandleSMTPClient(socket);                    
-                    HandlePOP3Client(socket, inbox);
-
-                    if (mails != null) 
-                        { 
-                            foreach (string mail in mails)
-                            {
-                                inbox.Add(mail);
-                            }
-                        }
-                    }
-                    Console.ReadKey();
-                    socket.Close();
-            }
+            HandlePOP3Client(iep_pop, inbox);
+            HandleSMTPClient(iep_smtp);                    
+            
+            Console.ReadKey();
         }
 
         // This is enum for keeping up with the state of the conversation
@@ -63,59 +42,141 @@ namespace STMPServer
             UserState,
             PassState
         }
+                
+        public static void threadListenPop(object obj)
+        {
+            Socket scon = obj as Socket;
+            byte[] data = new byte[2048];
+            IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
+            EndPoint Remote = (EndPoint)(sender);
+            List<string> inbox = new List<string> { "asd", "asdasd" }; // temporary
+            try
+            {
+                scon.Listen(1);
+                Socket newSocket = scon.Accept();
+                string ip = ((IPEndPoint)(newSocket.RemoteEndPoint)).Address.ToString();
+                string asiakas_port = ((IPEndPoint)(newSocket.RemoteEndPoint)).Port.ToString();
+                Console.WriteLine("Uusi asiakas: {0} portista: {1}", ip, asiakas_port);
 
-        
+                POPTila tila = POPTila.Aloitus;
+                AuthState authState = AuthState.UserState;
 
-        private static void HandlePOP3Client(Socket socket, List<string> inbox)
-        {
-            Socket asiakas = socket.Accept();
-            string ip = ((IPEndPoint)(asiakas.RemoteEndPoint)).Address.ToString();
-            string asiakas_port = ((IPEndPoint)(asiakas.RemoteEndPoint)).Port.ToString();
-            Console.WriteLine("Uusi asiakas: {0} portista: {1}", ip, asiakas_port);
+                bool keskustelu = true;
 
-            POPTila tila = POPTila.Aloitus;
-            AuthState authState = AuthState.UserState;
+                // 10min timeout jos ei vastaa?
+                while (keskustelu)
+                {
+                    byte[] buffer = new byte[2048];
+                    string asiakas_vastaus = "";
+                    int state;
+                    switch (tila)
+                    {
+                        case POPTila.Aloitus:
+                            VastaaAsiakas("+OK TIES323 POP3 server ready", newSocket);
+                            tila = POPTila.Authorization;
+                            break;
+                        case POPTila.Authorization:
+                            newSocket.Receive(buffer);
+                            asiakas_vastaus = TrimVastaus(Encoding.UTF8.GetString(buffer), newSocket);
 
-            bool keskustelu = true;
+                            state = CheckAuthorization(asiakas_vastaus, authState, newSocket);
+                            if (state == 1) { authState = AuthState.PassState; }
+                            if (state == 2) { authState = AuthState.UserState; tila = POPTila.Transaction; }
+                            if (state == 3) { keskustelu = false; }
+                            break;
+                        case POPTila.Transaction:
+                            newSocket.Receive(buffer);
+                            asiakas_vastaus = TrimVastaus(Encoding.UTF8.GetString(buffer), newSocket);
 
-            // 10min timeout jos ei vastaa?
-            while(keskustelu)
+                            state = HandleTransaction(asiakas_vastaus, newSocket, inbox);
+                            if (state == 1) { tila = POPTila.Update; }
+                            break;
+                        case POPTila.Update:
+                            HandleQuit(newSocket);
+                            keskustelu = false;
+                            break;
+                        default:
+                            VastaaAsiakas("Some error happened... shutting down", newSocket);
+                            keskustelu = false;
+                            break;
+                    }
+                }
+            }
+            catch (SocketException ex)
             {
-                byte[] buffer = new byte[2048];
-                string asiakas_vastaus = "";
-                int state;
-                switch (tila)
-                {
-                    case POPTila.Aloitus:
-                        VastaaAsiakas("+OK TIES323 POP3 server ready", asiakas);
-                        tila = POPTila.Authorization;
-                        break;
-                    case POPTila.Authorization:
-                        asiakas.Receive(buffer);
-                        asiakas_vastaus = TrimVastaus(Encoding.UTF8.GetString(buffer), asiakas);
+                Console.WriteLine(ex.Message);
+            }
+        }
 
-                        state = CheckAuthorization(asiakas_vastaus, authState, asiakas);
-                        if (state == 1) { authState = AuthState.PassState; }
-                        if (state == 2) { authState = AuthState.UserState; tila = POPTila.Transaction; }
-                        if (state == 3) { keskustelu = false; }
-                        break;
-                    case POPTila.Transaction:
-                        asiakas.Receive(buffer);
-                        asiakas_vastaus = TrimVastaus(Encoding.UTF8.GetString(buffer), asiakas);
+        public static void threadListenSmtp(object obj)
+        {
+            Socket scon = obj as Socket;
+            byte[] data = new byte[2048];
+            IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
+            EndPoint Remote = (EndPoint)(sender);
+
+            try
+            {
+                scon.Listen(1);
+                Socket newSocket = scon.Accept();
 
-                        state = HandleTransaction(asiakas_vastaus, asiakas, inbox);
-                        if(state == 1) { tila = POPTila.Update; }
-                        break;
-                    case POPTila.Update:
-                        HandleQuit(asiakas);
-                        keskustelu = false;
-                        break;
-                    default:
-                        VastaaAsiakas("Some error happened... shutting down", asiakas);
-                        keskustelu = false;
-                        break;
+                string ip = ((IPEndPoint)(newSocket.RemoteEndPoint)).Address.ToString();
+                string asiakas_port = ((IPEndPoint)(newSocket.RemoteEndPoint)).Port.ToString();
+                Console.WriteLine("Uusi asiakas: {0} portista: {1}", ip, asiakas_port);
+                // Aloitetaan keskustelu
+                newSocket.Send(Encoding.UTF8.GetBytes("220 TIES323 Postipalvelin\r\n"));
+                bool keskustelu = true;
+                bool data_vipu = false;
+                List<string> mail = new List<string>();
+
+                while (keskustelu)
+                {
+                    byte[] buffer = new byte[2048];
+                    newSocket.Receive(buffer);
+                    string asiakas_vastaus = Encoding.UTF8.GetString(buffer);
+                    Console.WriteLine("[{0}:{1}]: {2}", ip, asiakas_port, asiakas_vastaus);
+                    string[] lines = asiakas_vastaus.Split(
+                        new[] { "\r\n", "\r", "\n" },
+                            StringSplitOptions.None
+                        );
+
+                    int tila = 0;
+                    if (data_vipu)
+                    {
+                        mail.Add(ValidoiData(lines, newSocket));
+                        tila = 0;
+                    }
+                    else
+                    {
+                        tila = ValidoiVastaus(lines[0], newSocket, data_vipu);
+                    }
+                    switch (tila)
+                    {
+                        case 1:
+                            data_vipu = true;
+                            break;
+                        case 2:
+                            newSocket.Close();
+                            keskustelu = false;
+                            break;
+                        default:
+                            data_vipu = false;
+                            break;
+                    }
                 }
             }
+            catch (SocketException ex)
+            {
+                Console.WriteLine(ex.Message);
+            }
+        }
+
+        private static void HandlePOP3Client(IPEndPoint iep, List<string> inbox)
+        {
+            Socket asiakas = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+            asiakas.Bind(iep);
+            Thread thread = new Thread(threadListenPop);
+            thread.Start(asiakas);
         }
 
         static void HandleQuit(Socket socket)
@@ -213,54 +274,12 @@ namespace STMPServer
             return tila;
         }
 
-        private static List<string> HandleSMTPClient(Socket socket)
+        private static void HandleSMTPClient(IPEndPoint iep)
         {
-            Socket asiakas = socket.Accept();
-            string ip = ((IPEndPoint)(asiakas.RemoteEndPoint)).Address.ToString();
-            string asiakas_port = ((IPEndPoint)(asiakas.RemoteEndPoint)).Port.ToString();
-            Console.WriteLine("Uusi asiakas: {0} portista: {1}", ip, asiakas_port);
-            // Aloitetaan keskustelu
-            asiakas.Send(Encoding.UTF8.GetBytes("220 TIES323 Postipalvelin\r\n"));
-            bool keskustelu = true;
-            bool data_vipu = false;
-            List<string> mail = new List<string>();
-
-            while (keskustelu)
-            {
-                byte[] buffer = new byte[2048];
-                asiakas.Receive(buffer);
-                string asiakas_vastaus = Encoding.UTF8.GetString(buffer);
-                Console.WriteLine("[{0}:{1}]: {2}", ip, asiakas_port, asiakas_vastaus);
-                string[] lines = asiakas_vastaus.Split(
-                    new[] { "\r\n", "\r", "\n" },
-                        StringSplitOptions.None
-                    );
-
-                int tila = 0;
-                if (data_vipu)
-                {
-                    mail.Add(ValidoiData(lines, asiakas));
-                    tila = 0;
-                }
-                else
-                {
-                    tila = ValidoiVastaus(lines[0], asiakas, data_vipu);
-                }
-                switch (tila)
-                {
-                    case 1:
-                        data_vipu = true;
-                        break;
-                    case 2:
-                        asiakas.Close();
-                        keskustelu = false;
-                        break;
-                    default:
-                        data_vipu = false;
-                        break;
-                }
-            }
-            return mail;
+            Socket asiakas = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+            asiakas.Bind(iep);
+            Thread thread = new Thread(threadListenSmtp);
+            thread.Start(asiakas);
         }
 
         static int ValidoiVastaus(string vastaus, Socket socket, bool data_vipu)
diff --git a/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/STMPServer.dll b/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/STMPServer.dll
index 5aacbee811571455c5cc3d6be665f447340d20b4..1cea3856cbad54c45ea0c983c33dc563a8c60c35 100644
Binary files a/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/STMPServer.dll and b/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/STMPServer.dll differ
diff --git a/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/STMPServer.pdb b/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/STMPServer.pdb
index 66df8a263d6a993254f87c1229fb1a6270accfdb..a39a891a849b207426e555e81cfd1e1513fe2037 100644
Binary files a/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/STMPServer.pdb and b/SMTPServer/STMPServer/bin/Debug/netcoreapp3.1/STMPServer.pdb differ
diff --git a/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.csproj.CoreCompileInputs.cache b/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.csproj.CoreCompileInputs.cache
index 0eb597ec5d669c89db0ea024342bb9e58e9daf02..6828e096f7c3614396ceeb9d60a8f1d4e4e8d7fa 100644
--- a/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.csproj.CoreCompileInputs.cache
+++ b/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.csproj.CoreCompileInputs.cache
@@ -1 +1 @@
-1f9858c49b57c0e519074dd288db3e15bdd662aa
+1fedd4c88f277ea671e1c3b9a1fedf5a20b2639a
diff --git a/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.csprojAssemblyReference.cache b/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.csprojAssemblyReference.cache
index 2e2e4cd48ef53623d9b1b2ede269e8059601fa08..308f84f1bd32b1f7e1467356eb1ac40d7da08d5e 100644
Binary files a/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.csprojAssemblyReference.cache and b/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.csprojAssemblyReference.cache differ
diff --git a/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.dll b/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.dll
index 5aacbee811571455c5cc3d6be665f447340d20b4..1cea3856cbad54c45ea0c983c33dc563a8c60c35 100644
Binary files a/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.dll and b/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.dll differ
diff --git a/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.pdb b/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.pdb
index 66df8a263d6a993254f87c1229fb1a6270accfdb..a39a891a849b207426e555e81cfd1e1513fe2037 100644
Binary files a/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.pdb and b/SMTPServer/STMPServer/obj/Debug/netcoreapp3.1/STMPServer.pdb differ