all important parts finished.

Only thing left is to annotate the code.