Improved haskell code