Documentation + minor refactoring