Split out some utils and update tests to use them