Documentation extended and some minor refactorings