refactor to haskell