Worth tidying this behaviour into a module? Appears reasonably self contained.