More robust and correct way to parse messages from client