Added options to clear data and refactored code.