Made the source more robust.
Improved a lot ot javadoc, organized some code and also implemented some tests.