Refactoring and adding documentations