Duplicated code. Bleurgh. Can we unify this somehow?