Improved Haskell code