Move the mapping code into its own file.