Some refactoring to packages and to the code. More comments added.