rewrite with using template haskell