I looked at you code and see that you are using the internal OSC, I would not spend much time de-bugging until these are changed to externals.
99.99% of the time internal OSC are not reliable enough for serial com.
Go with a "resonator" the kind with three pins, and built in caps.
Bookmarks