Rightyo, thanks for all the help blokes. I got it all sorted out.
It may not be pretty, but it works a treat.

And it fits in the codespace.