To tell you the truth I didn't really know about this algorithm.
I just went at the problem function by function and this is what I ended up with.