Google stated several times in the past that there is no bias in how they treat TLDs. All should be the same and I haven't seen any case studies ever proving either way.

Does the order of the code snippets play a role? Is it correct in the above example?

Identify and block bots by user-agent string.