refactoring and remove useless function
add comments
add tests