This should be factored out into a seperate PR.