extracted serial handling from nano