Refactoring, Improved Testing.

Refactoring to match standard library naming patterns for networking
functions etc. Greatly Improved testing, as well as some improvements
to error handling and debugging.