modified to run on current ghc (7.6.3)