Cleaned Up the Code

Moved some of the socket writing methods into a separate file.

More clean up to come.