That is something that I think many of us forget to do: Thank the less than friendly people who are just doing their jobs. None of us like to be put through the mill, but it's part of crossing a border. We are so fortunate that crossing is as easy as it is.
My sweetie always took out his earrings, we approached the border without sunglasses, passports out the window and remembering to only answer questions that were asked. That was always hard for me.
I also had the pet paperwork in my hand but didn't offer it unless asked.
They have a tough job that I would not be willing to do. They are trying to protect us.