Added some javadoc and logging, fixed all open bugs, some refactorings