this function looks very copy/pasted.