Second order theory of flow in three dimensional deforming media