working serial cpp version