Removed dependency on template haskell.
Corrected a few minor mistakes due to externalising TH.