Added exception handling on insert and remove
Created a new class (TCPConnection) to shorten the code