some refactoring, test and updated documentation