Pull request: Closes #469 Move migration code into its own module

#469