Code Cleanup

- Removed debugging and redundant code.
- Removed socket cast.
- Added diagnostic message on handshake fail.