Cleaned up sockets and refactored getting ready for secure APis