Refactor merging into separate module to clean up code.