Fixed some serial stuff to make it more robust