It'd be great to have some tests for this function as well.