refactoring and add clear method