implemented error handling, moved message sending and receiving logic to send_message method which will be implemented later.