Added v3 - implemented in Haskell, roughly tested