Move code out of test and into its own file