Refactoring, more documentation