diff --git a/dune/stuff/common/math.hh b/dune/stuff/common/math.hh
index 9cf42afd48eb6b368eb98038bcec4f53c0c22eb0..c41d525f05703afe446b02efcd417fe44151fbf4 100644
--- a/dune/stuff/common/math.hh
+++ b/dune/stuff/common/math.hh
@@ -33,7 +33,7 @@ namespace boost {
 namespace math {
 //! isinf specialization for Dune::StraightenBlockVector
 template <class BlockVectorImp, class DofImp>
-#if DUNE_VERSION_NEWER(DUNE_FEM, 1, 4)
+#if DUNE_VERSION_NEWER(DUNE_FEM, 1, 5)
 inline bool isinf(const Dune::Fem::StraightenBlockVector<BlockVectorImp, DofImp>& x)
 {
 #else
diff --git a/dune/stuff/common/ranges.hh b/dune/stuff/common/ranges.hh
index eb20974f691a910c9033eaec43b331a933fc3297..952417c65d8ef7c63be2e72ac3459356f638e073 100644
--- a/dune/stuff/common/ranges.hh
+++ b/dune/stuff/common/ranges.hh
@@ -10,7 +10,8 @@
 #include <dune/grid/common/gridview.hh>
 #include <boost/serialization/static_warning.hpp>
 
-#ifdef HAVE_DUNE_FEM
+#if HAVE_DUNE_FEM
+#include <dune/fem/version.hh>
 #include <dune/fem/function/common/discretefunction.hh>
 #include <dune/fem/gridpart/common/gridpart.hh>
 #endif
@@ -19,7 +20,7 @@
 namespace std {
 
 
-#ifdef HAVE_DUNE_FEM
+#if HAVE_DUNE_FEM
 
 template <class DiscreteFunctionTraits>
 auto begin(const Dune::DiscreteFunctionInterface<DiscreteFunctionTraits>& func) -> decltype(func.dbegin())
@@ -143,7 +144,7 @@ intersectionRange(const Dune::GridView<GridViewTraits>& gridview,
                            typename Dune::GridView<GridViewTraits>::template Codim<0>::Entity>(gridview, entity);
 }
 
-#ifdef HAVE_DUNE_FEM
+#if defined(HAVE_DUNE_FEM) && HAVE_DUNE_GRID
 
 template <class GridPartTraits>
 IntersectionRange<Dune::GridPartInterface<GridPartTraits>,