Added handshake test, and fixed bugs in handshakes