As requested - trails code

Hi, as requested, I'm submitting a pull request for you.
David