diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -32,6 +32,12 @@
 
 This package tries to use latex labels and references if output type is LaTeX. It also tries to supplement rudimentary LaTeX configuration that should mimic metadata configuration by setting `header-includes` variable.
 
+## Caveats
+
+### LaTeX output and `--include-in-header`
+
+pandoc-crossref uses metadata variable `header-includes` to add LaTeX definitions to output. However, Pandoc's command line option `--include-in-header`/`-H` overrides this variable. If you need to use `--include-in-header`, add pandoc-crossref-specific definitions as well. See [LaTeX customization](#latex-customization) for more information.
+
 ## Syntax
 
 Syntax is loosely based on discussion in <https://github.com/jgm/pandoc/issues/813>
diff --git a/lib/Text/Pandoc/CrossRef/References/Accessors.hs b/lib/Text/Pandoc/CrossRef/References/Accessors.hs
--- a/lib/Text/Pandoc/CrossRef/References/Accessors.hs
+++ b/lib/Text/Pandoc/CrossRef/References/Accessors.hs
@@ -1,19 +1,35 @@
+{-# LANGUAGE RecordWildCards #-}
 module Text.Pandoc.CrossRef.References.Accessors where
 
 import Text.Pandoc.CrossRef.References.Types
-import Text.Pandoc.CrossRef.Util.Accessor
+import Data.Accessor
 
 imgRefs' :: Accessor References RefMap
-imgRefs' new r@References{imgRefs=old} = (old, r{imgRefs=new})
+imgRefs' = accessor
+  (\References{..} -> imgRefs)
+  (\a r -> r{imgRefs=a})
 
 eqnRefs' :: Accessor References RefMap
-eqnRefs' new r@References{eqnRefs=old} = (old, r{eqnRefs=new})
+eqnRefs' = accessor
+  (\References{..} -> eqnRefs)
+  (\a r -> r{eqnRefs=a})
 
 tblRefs' :: Accessor References RefMap
-tblRefs' new r@References{tblRefs=old} = (old, r{tblRefs=new})
+tblRefs' = accessor
+  (\References{..} -> tblRefs)
+  (\a r -> r{tblRefs=a})
 
 lstRefs' :: Accessor References RefMap
-lstRefs' new r@References{lstRefs=old} = (old, r{lstRefs=new})
+lstRefs' = accessor
+  (\References{..} -> lstRefs)
+  (\a r -> r{lstRefs=a})
 
 secRefs' :: Accessor References RefMap
-secRefs' new r@References{secRefs=old} = (old, r{secRefs=new})
+secRefs' = accessor
+  (\References{..} -> secRefs)
+  (\a r -> r{secRefs=a})
+
+curChap' :: Accessor References Index
+curChap' = accessor
+  (\References{..} -> curChap)
+  (\a r -> r{curChap=a})
diff --git a/lib/Text/Pandoc/CrossRef/References/Blocks.hs b/lib/Text/Pandoc/CrossRef/References/Blocks.hs
--- a/lib/Text/Pandoc/CrossRef/References/Blocks.hs
+++ b/lib/Text/Pandoc/CrossRef/References/Blocks.hs
@@ -8,18 +8,22 @@
 
 import Text.Pandoc.Definition
 import Text.Pandoc.Generic
+import Text.Pandoc.Walk
 import Text.Pandoc.Builder (text, toList)
 import Text.Pandoc.Shared (stringify, normalizeSpaces)
-import Control.Monad.State
+import Control.Monad.State hiding (get, modify)
 import Data.List
 import qualified Data.Map as M
 
-import Text.Pandoc.CrossRef.Util.Accessor
+import Data.Accessor
+import Data.Accessor.Monad.Trans.State
 import Text.Pandoc.CrossRef.References.Types
 import Text.Pandoc.CrossRef.References.Accessors
 import Text.Pandoc.CrossRef.Util.Util
 import Text.Pandoc.CrossRef.Util.Options
 import Text.Pandoc.CrossRef.Util.Template
+import Control.Applicative
+import Prelude
 
 replaceBlocks :: Options -> Block -> WS Block
 replaceBlocks opts (Header n (label, cls, attrs) text')
@@ -28,14 +32,14 @@
                  then "sec:"++label
                  else label
     unless ("unnumbered" `elem` cls) $ do
-      modify $ \r@References{curChap=cc} ->
+      modify curChap' $ \cc ->
         let ln = length cc
             cl = lookup "label" attrs
             inc l = init l ++ [(fst (last l) + 1, cl)]
             cc' | ln > n = inc $ take n cc
                 | ln == n = inc cc
                 | otherwise = cc ++ take (n-ln-1) (zip [1,1..] $ repeat Nothing) ++ [(1,cl)]
-        in r{curChap=cc'}
+        in cc'
       when ("sec:" `isPrefixOf` label') $ replaceAttrSec label' text' secRefs'
     return $ Header n (label', cls, attrs) text'
 #if MIN_VERSION_pandoc(1,16,0)
@@ -114,29 +118,33 @@
             Para caption'
           , CodeBlock ([], classes, attrs) code
           ]
-replaceBlocks opts x = bottomUpM (replaceInlines opts) x
+replaceBlocks opts x = walkM (replaceInlines opts) x
 
-replaceInlines :: Options -> [Inline] -> WS [Inline]
-replaceInlines opts (Span (label,_,attrs) [Math DisplayMath eq]:ils')
+replaceInlines :: Options -> Inline -> WS Inline
+replaceInlines opts (Span (label,_,attrs) [Math DisplayMath eq])
   | "eq:" `isPrefixOf` label
   = case outFormat opts of
       f | isFormat "latex" f ->
         let eqn = "\\begin{equation}"++eq++"\\label{"++label++"}\\end{equation}"
-        in return $ RawInline (Format "tex") eqn : ils'
+        in return $ RawInline (Format "tex") eqn
       _ -> do
         idxStr <- replaceAttr opts label (lookup "label" attrs) [] eqnRefs'
         let eq' = eq++"\\qquad("++stringify idxStr++")"
-        return $ Math DisplayMath eq' : ils'
+        return $ Math DisplayMath eq'
 #if MIN_VERSION_pandoc(1,16,0)
-replaceInlines opts (Image attr@(label,_,attrs) alt img:ils')
+replaceInlines opts x@(Image attr@(label,_,attrs) alt img)
   | "fig:" `isPrefixOf` label, "fig:" `isPrefixOf` snd img
   = do
-    idxStr <- replaceAttr opts label (lookup "label" attrs) alt imgRefs'
-    let alt' = case outFormat opts of
-          f | isFormat "latex" f ->
-            RawInline (Format "tex") ("\\label{"++label++"}") : alt
-          _  -> applyTemplate idxStr alt $ figureTemplate opts
-    return $ Image attr alt' img : ils'
+    hasLab <- M.member label <$> (get imgRefs')
+    if hasLab
+    then return x
+    else do
+      idxStr <- replaceAttr opts label (lookup "label" attrs) alt imgRefs'
+      let alt' = case outFormat opts of
+            -- f | isFormat "latex" f ->
+              -- RawInline (Format "tex") ("\\label{"++label++"}") : alt
+            _  -> applyTemplate idxStr alt $ figureTemplate opts
+      return $ Image attr alt' img
 #else
 #endif
 replaceInlines _ x = return x
@@ -175,9 +183,9 @@
 replaceAttr o label refLabel title prop
   = do
     chap  <- take (chapDepth o) `fmap` gets curChap
-    i     <- (1+) `fmap` gets (M.size . M.filter ((==chap) . init . refIndex) . getProp prop)
+    i     <- (1+) `fmap` (M.size . M.filter ((==chap) . init . refIndex) <$> get prop)
     let index = chap ++ [(i, refLabel)]
-    modify $ modifyProp prop $ M.insert label RefRec {
+    modify prop $ M.insert label RefRec {
       refIndex= index
     , refTitle=normalizeSpaces title
     }
@@ -187,7 +195,7 @@
 replaceAttrSec label title prop
   = do
     index  <- gets curChap
-    modify $ modifyProp prop $ M.insert label RefRec {
+    modify prop $ M.insert label RefRec {
       refIndex=index
     , refTitle=normalizeSpaces title
     }
diff --git a/lib/Text/Pandoc/CrossRef/References/Refs.hs b/lib/Text/Pandoc/CrossRef/References/Refs.hs
--- a/lib/Text/Pandoc/CrossRef/References/Refs.hs
+++ b/lib/Text/Pandoc/CrossRef/References/Refs.hs
@@ -2,18 +2,21 @@
 
 import Text.Pandoc.Definition
 import Text.Pandoc.Shared (normalizeInlines, normalizeSpaces)
-import Control.Monad.State
+import Control.Monad.State hiding (get, modify)
 import Data.List
 import Data.Maybe
 import Data.Function
 import qualified Data.Map as M
 import Control.Arrow as A
 
-import Text.Pandoc.CrossRef.Util.Accessor
+import Data.Accessor
+import Data.Accessor.Monad.Trans.State
 import Text.Pandoc.CrossRef.References.Types
 import Text.Pandoc.CrossRef.References.Accessors
 import Text.Pandoc.CrossRef.Util.Util
 import Text.Pandoc.CrossRef.Util.Options
+import Control.Applicative
+import Prelude
 
 replaceRefs :: Options -> [Inline] -> WS [Inline]
 replaceRefs opts (Cite cits _:xs)
@@ -114,7 +117,7 @@
 
 getRefIndex :: String -> Citation -> WS (Maybe Index, [Inline])
 getRefIndex prefix Citation{citationId=cid,citationSuffix=suf}
-  = (\x -> (x,suf)) `fmap` gets (fmap refIndex . M.lookup lab . getProp prop)
+  = (\x -> (x,suf)) `fmap` (fmap refIndex . M.lookup lab <$> get prop)
   where
   prop = lookupUnsafe prefix accMap
   lab = prefix ++ getLabelWithoutPrefix cid
diff --git a/lib/Text/Pandoc/CrossRef/Util/Accessor.hs b/lib/Text/Pandoc/CrossRef/Util/Accessor.hs
deleted file mode 100644
--- a/lib/Text/Pandoc/CrossRef/Util/Accessor.hs
+++ /dev/null
@@ -1,17 +0,0 @@
-module Text.Pandoc.CrossRef.Util.Accessor (Accessor, setProp, getProp, modifyProp) where
-
--- from data-accessor http://www.haskell.org/haskellwiki/Record_access
--- Copyright (c) Henning Thielemann <haskell@henning-thielemann.de>, Luke Palmer <lrpalmer@gmail.com>
--- Licensed under BSD3 -- see BSD3.md
-type Accessor r a  =  a -> r -> (a, r)
-
-setProp :: Accessor r a -> a -> r -> r
-setProp f x = snd . f x
-
-getProp :: Accessor r a -> r -> a
-getProp f = fst . f undefined
-
-modifyProp :: Accessor r a -> (a -> a) -> r -> r
-modifyProp f g rOld =
-   let (a,rNew) = f (g a) rOld
-   in  rNew
diff --git a/pandoc-crossref.cabal b/pandoc-crossref.cabal
--- a/pandoc-crossref.cabal
+++ b/pandoc-crossref.cabal
@@ -2,7 +2,7 @@
 -- documentation, see http://haskell.org/cabal/users-guide/
 
 name:                pandoc-crossref
-version:             0.1.6.3
+version:             0.1.6.4
 synopsis:            Pandoc filter for cross-references
 description:         pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them.
 license:             GPL-2
@@ -24,7 +24,7 @@
 source-repository this
   type: git
   location: https://github.com/lierdakil/pandoc-crossref
-  tag: v0.1.6.3
+  tag: v0.1.6.4
 
 library
   exposed-modules:     Text.Pandoc.CrossRef
@@ -35,7 +35,6 @@
                      , Text.Pandoc.CrossRef.References.Refs
                      , Text.Pandoc.CrossRef.References.Types
                      , Text.Pandoc.CrossRef.Util.Settings
-                     , Text.Pandoc.CrossRef.Util.Accessor
                      , Text.Pandoc.CrossRef.Util.Meta
                      , Text.Pandoc.CrossRef.Util.Options
                      , Text.Pandoc.CrossRef.Util.Template
@@ -53,6 +52,8 @@
                      , yaml >= 0.8 && <0.9
                      , data-default >= 0.4 && <0.6
                      , bytestring >=0.9 && <0.11
+                     , data-accessor >= 0.2.2.7 && < 0.3.0.0
+                     , data-accessor-transformers >= 0.2.1.7 && < 0.3.0.0
   hs-source-dirs:      lib
   Ghc-Options:         -Wall
   default-language:    Haskell2010
@@ -89,6 +90,8 @@
                  , bytestring >=0.9 && <0.11
                  , hspec
                  , process >=1 && <1.5
+                 , data-accessor >= 0.2.2.7 && < 0.3.0.0
+                 , data-accessor-transformers >= 0.2.1.7 && < 0.3.0.0
                  , pandoc-crossref
   other-modules: Native
   Ghc-Options:  -rtsopts -Wall -fno-warn-unused-do-bind -threaded
diff --git a/test/test-pandoc-crossref.hs b/test/test-pandoc-crossref.hs
--- a/test/test-pandoc-crossref.hs
+++ b/test/test-pandoc-crossref.hs
@@ -16,7 +16,7 @@
 import Text.Pandoc.CrossRef.Util.Util
 import Text.Pandoc.CrossRef.References.Types
 import Text.Pandoc.CrossRef.Util.Settings
-import Text.Pandoc.CrossRef.Util.Accessor
+import Data.Accessor
 import Text.Pandoc.CrossRef.References.Accessors
 import qualified Text.Pandoc.CrossRef.References.Blocks as References.Blocks
 import qualified Text.Pandoc.CrossRef.References.Refs as References.Refs
@@ -247,10 +247,10 @@
 refRec''' ref (c,i) = [(ref, RefRec{refIndex=[(c,Nothing), (i,Nothing)],refTitle=toList $ text []})]
 
 testRefs' :: String -> [Int] -> [Int] -> Accessor References (M.Map String RefRec) -> String -> Expectation
-testRefs' p l1 l2 prop res = testRefs (para $ citeGen p l1) (setProp prop (refGen p l1 l2) def) (para $ text res)
+testRefs' p l1 l2 prop res = testRefs (para $ citeGen p l1) (setVal prop (refGen p l1 l2) def) (para $ text res)
 
 testRefs'' :: String -> [Int] -> [(Int, Int)] -> Accessor References (M.Map String RefRec) -> String -> Expectation
-testRefs'' p l1 l2 prop res = testRefs (para $ citeGen p l1) (setProp prop (refGen' p l1 l2) def) (para $ text res)
+testRefs'' p l1 l2 prop res = testRefs (para $ citeGen p l1) (setVal prop (refGen' p l1 l2) def) (para $ text res)
 
 testBlocks :: Blocks -> (Blocks, References) -> Expectation
 testBlocks = testState f def
