Restructure haskell code