Rearranged core functionality of the mesh package into separate files.