major haskell code refactor