sped up Haskell version