#46 refactoring Server: finish handshake function