Updated current brnach checking.
Reorganized a lot of code.
Wrote the first tests!