making it work in C++
Re-structring haskell code.