[DOX,FIX] more refactoring, more tests, more DOX