Implemented keepalive code
Fixed keepalive code
Changed handshake code to prevent the device from locking up