serial code updated (still buggy)