I'm confident there is a more elegant way to do this, but it's also bed time. Will give it more thought later :)