written for ruby and haskell - still need to test