implemented clear() and refactoring