This whole function can be reduced to `fn`.