To get anywhere with this, I'd like to see the compilable code that you ran on the Uno and the code that ran on the Mega. They can't be the same, if only because you're using Serial1 in the Mega version.
It would be nice too if you would run all the code you post and confirm what it does.