Free dynamics spaces
Use cmake. Move utility function to a separate file.