This function and the one above are practically identical... is there any way we can DRY this out a bit?