should work, but i'm not shure
must be tailrecursive otherwise its to expensive
commented it out
compile errors fixed