Huge Update - Algorithms Part 1

Added a text file write when you close the socket. Also, tried to
implement Dan's algorithm. Not fully functional yet.